package com.lws.rxutils.asynconce;

import androidx.annotation.NonNull;

import io.reactivex.rxjava3.core.Completable;
import io.reactivex.rxjava3.core.Flowable;
import io.reactivex.rxjava3.core.Maybe;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Single;
import io.reactivex.rxjava3.functions.Action;
import io.reactivex.rxjava3.functions.Supplier;


/**
 * @author liuwanshun
 */
public class RxAsyncOnce {

    static final String TAG = "RxAsyncOnce";
    static boolean debug = true;

    public static void setDebug(boolean debug) {
        RxAsyncOnce.debug = debug;
    }

    private RxAsyncOnce() {
    }

    public static CompleteRxAsyncOnce create(@NonNull Completable completable) {
        return new CompleteRxAsyncOnce(completable);
    }

    public static CompleteRxAsyncOnce create(@NonNull Action action) {
        return new CompleteRxAsyncOnce(Completable.fromAction(action));
    }

    public static <T> SingleRxAsyncOnce<T> create(@NonNull Supplier<T> supplier) {
        return new SingleRxAsyncOnce<>(Single.fromSupplier(supplier));
    }

    public static <T> SingleRxAsyncOnce<T> create(@NonNull Single<T> single) {
        return new SingleRxAsyncOnce<>(single);
    }

    public static <T> FlowableRxAsyncOnce<T> create(@NonNull Flowable<T> flowable) {
        return new FlowableRxAsyncOnce<>(flowable);
    }

    public static <T> ObservableRxAsyncOnce<T> create(@NonNull Observable<T> observable) {
        return new ObservableRxAsyncOnce<>(observable);
    }

    public static <T> MaybeRxAsyncOnce<T> create(@NonNull Maybe<T> maybe) {
        return new MaybeRxAsyncOnce<>(maybe);
    }
}
